package com.nineclock.system.entity;


import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.nineclock.system.service.SysCompanyUserService;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;


@Slf4j
public class ExcelMemberListener extends AnalysisEventListener<ExcelMember> {

    private List<ExcelMember> memberList = new ArrayList<ExcelMember>();

    private SysCompanyUserService sysCompanyUserService;
    public ExcelMemberListener(){
    }
    public ExcelMemberListener(SysCompanyUserService sysCompanyUserService){
        this.sysCompanyUserService = sysCompanyUserService;
    }

    //解析每一行时触发
    @Override
    public void invoke(ExcelMember data, AnalysisContext context) {
        log.info("解析每一行的数据 , 数据内容: " + data);
        memberList.add(data);
    }

    //完全解析完毕后触发
    @Override
    public void doAfterAllAnalysed(AnalysisContext context) {
        sysCompanyUserService.handleParsedData(memberList);
    }

}